package com.example.neteasecloudmusic.ui.song_list_detail;

import com.example.neteasecloudmusic.bean.playListBean.PlayList;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.schedulers.Schedulers;

public class PlayListPresenter implements PlayContract.IPlayListPresenter {

    private PlayContract.IPlayListView playListView;
    private PlayContract.IPlayListModel playListModel;


    public PlayListPresenter(PlayContract.IPlayListView playListView) {
        playListModel = new PlayListModel();
        this.playListView = playListView;
    }

    @Override
    public void getPlayList(String id) {
        playListModel.getPlaylistData()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<PlayList>() {
                    @Override
                    public void accept(PlayList playList) throws Throwable {
                        playListView.getPlayListSuccess(playList);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Throwable {
                        playListView.getPlayListFailure(throwable);
                    }
                });
    }
}
